package com.hbnu.mapper;

import com.hbnu.domain.Books;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface BooksMapper {

    //查询所有图书方法
    @Select("select * from books;")
    List<Books> findAllBooks();

    //查询单个图书方法
    @Select("select * from books where bid=#{bid};")
    Books findBook(int bid);

    //查询书名方法
    @Select("select bname from books where bid=#{bid};")
    String findbName(int bid);

    //借书方法
    @Update("update books set bnumber=bnumber-1 where bid = #{bid};")
    int lendBook(int bid);

    //还书方法
    @Update("update books set bnumber=bnumber+1 where bid = #{bid};")
    int returnBook(int bid);

    //添加新书
    @Insert("insert into books(bname,bauthor,bpublisher,bnumber) values(#{bname},#{bauthor},#{bpublisher},#{bnumber});")
    int addBook(Books book);

    //修改图书
    @Update("update books set bname = #{bname},bauthor = #{bauthor},bpublisher = #{bpublisher},bnumber = #{bnumber} where bid = #{bid};")
    int updateBook(Books book);

    //删除图书
    @Delete("delete from books where bid = #{bid}")
    int deleteBook(int bid);
}
